use std::ptr::null;
use std::sync::Arc;
use tracing::info;
use crate::{CmdRequest, CmdResponse, Storage};
use crate::rocksdb_storage::RocksDbStorage;

pub mod cmd_service;

pub trait CmdService {
    // 解析用户的命令，并且返回response
    fn execute(self, store: &impl Storage) -> CmdResponse;
}

// 设置默认存储为RocksDB
pub struct Service<T = RocksDbStorage> {
    store_svc: Arc<StoreService<T>>,
}

// 在多线程中进行clone
pub struct StoreService<T> {
    store: T,
}

impl<T: Storage> Service<T> {
    pub fn new(s: T) -> Self {
        Service {
            store_svc: Arc::new(StoreService { store: s })
        }
    }

    // 执行命令
    pub async fn execute(&self, cmd_req: CmdRequest) -> CmdResponse {
        info!("Execute Command Before");
        let cmd_res = process_cmd(cmd_req, &self.store_svc.store);

    }
}